﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Data;
using EZCRS.HCMS.Entity;
using System.Data;
using System.Data.SqlClient;

namespace EZCRS.HCMS.SqlClient
{
    public class sql_AdmWebPageInfo:MainBase
    {
        private string SqlStr = "";
        #region 后台用户个性表
        /// <summary>
        /// 前台用户个性化信息
        /// </summary>
        /// <param name="Orgid"></param>
        /// <param name="Orgtype"></param>
        /// <returns></returns>
        public DataSet WebPageInfo_Item(string Orgid, string Orgtype)
        {
            try
            {
                string strSql = "";
                if (Orgtype != "")
                    strSql = "select * from hfg_org_domain where orgid=" + Orgid + " and orgtype=" + Orgtype + "";
                else
                    strSql = "select * from hfg_org_domain where orgid=" + Orgid + " ";
                return ExecSql.GetDataSet(strSql);
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 前台应用设置添加和修改
        /// <summary>
        /// 添加和修改后台用户个性表
        /// </summary>
        /// <returns></returns>
        public bool WebPageInfo_Add(string Orgtype, string Orgid, string Webdomain, string Noscroll, string Css, string Sloganresv, string Sloganmod, string Slogancxl, string Slogannewresv, string Emailfrom, string Emailalias, string Emailtitle, string Ratecode, string Languagetype, string Id)
        {
            SqlParameter[] pam = new SqlParameter[14];
            pam[0] = new SqlParameter("@orgtype", Orgtype);
            pam[1] = new SqlParameter("@orgid", Orgid);
            pam[2] = new SqlParameter("@webdomain", Webdomain);
            pam[3] = new SqlParameter("@noscroll", Noscroll);
            pam[4] = new SqlParameter("@css", Css);
            pam[5] = new SqlParameter("@sloganresv", Sloganresv);
            pam[6] = new SqlParameter("@sloganmod", Sloganmod);
            pam[7] = new SqlParameter("@slogancxl", Slogancxl);
            pam[8] = new SqlParameter("@slogannewresv", Slogannewresv);
            pam[9] = new SqlParameter("@emailfrom", Emailfrom);
            pam[10] = new SqlParameter("@emailalias", Emailalias);
            pam[11] = new SqlParameter("@emailtitle", Emailtitle);
            pam[12] = new SqlParameter("@ratecode", Ratecode);
            pam[13] = new SqlParameter("@languagetype", Languagetype);
            if (Id != "")
                SqlStr = "update hfg_org_domain set orgtype=@orgtype,orgid=@orgid,webdomain=@webdomain,noscroll=@noscroll,css=@css,sloganresv=@sloganresv,sloganmod=@sloganmod,slogancxl=@slogancxl,slogannewresv=@slogannewresv,emailfrom=@emailfrom,emailalias=@emailalias,emailtitle=@emailtitle,ratecode=@ratecode,languagetype=@languagetype where id=" + Id + "";
            else
                SqlStr = "insert into hfg_org_domain(orgtype,orgid,webdomain,noscroll,css,sloganresv,sloganmod,slogancxl,slogannewresv,emailfrom,emailalias,emailtitle,ratecode,languagetype) values(@orgtype,@orgid,@webdomain,@noscroll,@css,@sloganresv,@sloganmod,@slogancxl,@slogannewresv,@emailfrom,@emailalias,@emailtitle,@ratecode,@languagetype)";
            if (ExecSql.SqlExecNoquery(SqlStr, pam) > 0)
                return true;
            else
                return false;
        }
        #endregion

        #region
        /// <summary>
        /// 保存系统设置
        /// </summary>
        /// <param name="scorevalid"></param>
        /// <param name="scoretype"></param>
        /// <param name="roomchange"></param>
        /// <param name="scoreratechg"></param>
        /// <param name="scorebuy"></param>
        /// <param name="scoreratebuy"></param>
        /// <returns></returns>
        public bool savesetup(int gid, string haved, string scorevalid, string scoretype, string roomchange, string scoreratechg, string scorebuy, string scoreratebuy)
        {
            SqlParameter[] pam = new SqlParameter[6];
            pam[0] = new SqlParameter("@scorevalid", scorevalid);
            pam[1] = new SqlParameter("@scoretype", scoretype);
            pam[2] = new SqlParameter("@roomchange", roomchange);
            pam[3] = new SqlParameter("@scoreratechg", (roomchange == "1" && scoreratechg == "") ? "1000" : scoreratechg);
            pam[4] = new SqlParameter("@scorebuy", scorebuy);
            pam[5] = new SqlParameter("@scoreratebuy", (scorebuy == "1" && scoreratebuy == "") ? "1000" : scoreratebuy);
            string sqlstr = "";
            if (haved == "1")
                sqlstr = "update hfg_org_domain set scorevalid=@scorevalid,scoretype=@scoretype,roomchange=@roomchange,scoreratechg=@scoreratechg,scorebuy=@scorebuy,scoreratebuy=@scoreratebuy where  orgtype=0 and orgid=" + gid.ToString();
            else
                sqlstr = "insert into hfg_org_domain(orgtype,orgid,scorevalid,scoretype,roomchange,scoreratechg,scorebuy,scoreratebuy) values(0," + gid.ToString() + ",@scorevalid,@scoretype,@roomchange,@scoreratechg,@scorebuy,@scoreratebuy)";
            if (ExecSql.SqlExecNoquery(sqlstr, pam) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 返回购买积分的比率，0为未开通购买功能
        /// </summary>
        /// <param name="gid"></param>
        /// <returns></returns>
        public decimal buyscore_rate(int gid)
        {
            DataSet ds = ExecSql.GetDataSet("select scorebuy,scoreratebuy from hfg_org_domain where orgid=" + gid.ToString() + "");
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                if (dr["scorebuy"].ToString() == "False" || dr["scorebuy"].ToString() == "")
                    return 0;
                else
                    return Convert.ToDecimal(dr["scoreratebuy"].ToString());
            }
            return 0;
        }

        #endregion
    }
}
